/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.jinhe.tss.core.exception.BusinessException;

public class Helper {
    
    public static final String[] tss_db =  {"jdbc:oracle:thin:@localhost:1521:myoralce", "tss", "tss"};
    
    public static final String[] ums_db =  {"jdbc:oracle:thin:@localhost:1521:myoralce", "demo_ums", "ums"};
    public static final String[] pms_db =  {"jdbc:oracle:thin:@localhost:1521:myoralce", "demo_pms", "pms"};
    public static final String[] cms_db =  {"jdbc:oracle:thin:@localhost:1521:myoralce", "demo_cms", "cms"};
    
    public static void releaseConnection(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                throw new BusinessException("销毁数据库连接时候出错", e);
            }
        }
    }
    
    public static Connection getDB2Connection(String url, String user, String password){
        Connection conn = null;
        try {
            Class.forName("com.ibm.db2.jcc.DB2Driver");
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            throw new BusinessException("连接外部DB2数据库失败,请检查连接参数",e);
        } catch (ClassNotFoundException e) {
            throw new BusinessException("连接外部DB2数据库失败,驱动程序找不到",e);
        }
        return conn;
    }
    
    public static Connection getOracleConnection(String url, String user, String password){
        Connection conn = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            throw new BusinessException("连接Oracle数据库失败,请检查连接参数",e);
        } catch (ClassNotFoundException e) {
            throw new BusinessException("连接Oracle数据库失败,驱动程序找不到",e);
        }
        return conn;
    }
}

